import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Group, GroupMember } from '../domain/group';
import { Level, OrganizationLevelRelation } from '../domain/level';

@Injectable({
  providedIn: 'root'
})
export class GroupService {
  host:string = "http://localhost:8091/api";

  constructor(private httpClient: HttpClient) { }


  public saveMembers(groupMember: GroupMember){
    return this.httpClient.post(this.host+"/groups/addMembers",groupMember);
  }

  public getGroupMember(groupId: string){
    return this.httpClient.get<GroupMember>(this.host+"/groups/getGroupMember",{ params:{groupId:groupId}})
  }

  public getParents(organizationId: string, positionLevelId: string) {
    return this.httpClient.get<any>(this.host+"/groups/getParents",{ params:{organizationId:organizationId,positionLevelId:positionLevelId}})
  }

  public getTreeByParentId(parentId: string){
    return this.httpClient.get<any>(this.host+"/groups/getTreeByParentId",{ params:{parentId:parentId}})
  }

  public saveBatch(levels: Level[]){
    return this.httpClient.post(this.host+"/groups/batch",levels);
  }

  public save(level: Group){
    return this.httpClient.post<Group>(this.host+"/groups",level);
  }

  public saveRelations(levelRelations: OrganizationLevelRelation[]){
    return this.httpClient.post(this.host+"/groups/relations/batch",levelRelations);
  }

  public getModelName(){
    return this.httpClient.get<any>(this.host+"/groups/getModelName");
  }

  deleteBatch(ids$: any) {
    return this.httpClient.delete(this.host+"/groups/batch",{body:ids$});
  }
}
